package com.source.lightfowl.barcodeMachineGrantAndRecovery.controller;

import com.source.lightfowl.VO.BarcodeMachineRecoveryVO;
import com.source.lightfowl.barcodeMachineGrantAndRecovery.pojo.BarcodeMachineRecovery;
import com.source.lightfowl.barcodeMachineGrantAndRecovery.service.BarcodeMachineRecoveryService;
import com.source.lightfowl.syslog.annotation.LogAnnotation;
import com.source.lightfowl.utils.MyResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

/**
 * @Author: 谢春泳
 * @Description: 角标机回收管理控制器
 * @Date: 2020.3.16
 */
@Api(value = "脚标机回收管理",tags = "脚标机回收管理")
@RestController
@CrossOrigin
@RequestMapping("/barcodeMachineRecovery")
public class BarcodeMachineRecoveryController {
    @Autowired
    private BarcodeMachineRecoveryService barcodeMachineRecoveryService;

    /*
        查找全部
     */
    @ApiOperation(value = "查询全部数据")
    @GetMapping
    public MyResult findAll(){
        List<BarcodeMachineRecoveryVO> all = barcodeMachineRecoveryService.findAll();
        if(all!=null)
            return MyResult.build(0,"成功",all);
        else
            return MyResult.build(1,"结果为空");
    }

    //查找 分页
    @ApiOperation(value = "分页查询（传递两个参数：页数 个数/页）")
    @GetMapping("/barcodeMachineRecoveryFindAllPage")
    public MyResult findAllPage(int page,int pageNum){

        Page<BarcodeMachineRecovery> all = barcodeMachineRecoveryService.findAllPage(page,pageNum);
        if(all!=null)
            return MyResult.build(0,"成功",all);
        else
            return MyResult.build(1,"结果为空");
    }

    //根据id查
    @ApiOperation(value = "根据id查询")
    @GetMapping("/{id}")
    public MyResult findById(@PathVariable Integer id){
        BarcodeMachineRecoveryVO house = barcodeMachineRecoveryService.findById(id);
        if(house!=null)
            return MyResult.build(0,"成功",house);
        else
            return MyResult.build(1,"结果为空");
    }

    //根据脚标机的id查找
    @ApiOperation(value = "根据脚标机的id查询")
    @GetMapping("/findByBarcodeMachineId/{id}")
    public MyResult findByBarcodeMachineId(@PathVariable Integer id){
        List<BarcodeMachineRecovery> house = barcodeMachineRecoveryService.findByBarcodeMachineId(id);
        if(house!=null)
            return MyResult.build(0,"成功",house);
        else
            return MyResult.build(1,"结果为空");
    }
    //增加 修改
    @ApiOperation(value = "增加/修改 数据 ")
    @PostMapping
    @LogAnnotation(operEvent = "操作类型：添加/修改",operType = 2)
    public MyResult create(BarcodeMachineRecovery barcodeMachineRecovery){
        barcodeMachineRecoveryService.save(barcodeMachineRecovery);
        return MyResult.build(0,"成功");
    }

    //删除
    @ApiOperation("根据id删除数据")
    @DeleteMapping("/{id}")
    @LogAnnotation(operEvent = "操作类型：删除记录",operType = 3)
    public MyResult deleteById(@PathVariable Integer id){

        barcodeMachineRecoveryService.deleteById(id);
        return MyResult.build(0,"删除成功");

    }

    //删除 批量
    @ApiOperation(value = "批量删除数据：参数传递id的字符串 用英文的逗号分开")
    @DeleteMapping("/barcodeMachineRecoveryDeleteBatch")
    @LogAnnotation(operEvent = "操作类型：批量删除记录",operType = 4)
    public MyResult deleteBatch(String ids){    //注意：参数的分隔符逗号是英文的

        barcodeMachineRecoveryService.deleteBatch(ids);
        return MyResult.build(0,"删除成功");

    }
}
